package com.example.config;

import com.example.model.AnyUser;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

@Component
public class MyUserDetailsService implements UserDetailsService {

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        // TODO Auto-generated method stub
        //这里可以可以通过username（登录时输入的用户名）然后到数据库中找到对应的用户信息，并构建成我们自己的UserInfo来返回。


        //这里可以通过数据库来查找到实际的用户信息，这里我们先模拟下,后续我们用数据库来实现
        AnyUser userInfo = null;
        if(username.equals("admin"))
        {
            //假设返回的用户信息如下;
            userInfo = new AnyUser("admin", "admin", "ROLE_ADMIN", true,true,true, true);
        }else if(username.equals("user")) {
            userInfo = new AnyUser("user", "user", "ROLE_USER", true,true,true, true);
        }

        return userInfo;


    }
}

